package game.pong.views.components
{
	/**
	 * Abstract class, intended to be extended, not implemented
	 * Basic properties and behaviours for the user paddle and the computer one
	 */
	 
	import game.pong.events.SoundEvent;
	import mx.containers.Canvas;

	public class AbstractPaddle extends Canvas
	{
		/** Top bound of movement */
		public static var topBound : Number;
		
		/** Bottom bound of movement */
		public static var bottomBound : Number;
		
		/** Maximum amount the ball can bounce off in the Y direction */
		private static var maxBounceVYSkew : Number = 12;
		
		/**
		 * Bounce a ball off of the paddle.
		 * @param ball Ball to bounce
		 */
		public function bounce(ball : Ball) : void
		{
			dispatchEvent(new SoundEvent(SoundEvent.BOUNCE_PADDLE));
			// Reverse X direction and bounce horizontally
			ball.vX = -ball.vX;
			ball.x += ball.vX;
			
			// Calculate the relative position where the ball hit from the paddle's center
			var hitPos : Number = ball.y - (this.y + (this.height / 2) - ball.height);
			
			// Calculate the percentage from the paddle's center that the ball hit
			var percentFromCenter : Number = hitPos / this.height / 2;
			
			// Compute the amount to perturb the ball's VY
			var vyAdjust : Number = percentFromCenter * AbstractPaddle.maxBounceVYSkew;
			
			// Perturb VY based on the hit
			ball.vY += vyAdjust
		}
		
	}
}